import { ref } from 'vue'
import { getGoods as getGoodsApi } from '@/api/goodsInfo'
import { Good } from './types'

const useGetGoods = () => {
  const getGoodsLoading = ref(false)
  const goods = ref<Array<Good>>([])
  const goodTotal = ref(0)
  const getGoods = async (param: Good.GetGoods) => {
    getGoodsLoading.value = true
    const res = await getGoodsApi(param)
    goodTotal.value = Number(res.data.data.total)
    goods.value = res.data.data.rows
    getGoodsLoading.value = false
  }

  return {
    goods,
    goodTotal,
    getGoodsLoading,
    getGoods,
  }
}

export default useGetGoods
